import bean.JsonBean;
import com.google.gson.Gson;

import java.awt.print.Book;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        parseJson();
    }
    public static void parseJson(){
        String jsonStr = "{\n" +
                "    \"name\": \"zhangsan\",\n" +
                "    \"age\": 18,\n" +
                "    \"books\": [\n" +
                "      {\n" +
                "        \"name\": \"java\",\n" +
                "        \"author\": \"lisi\"\n" +
                "      },\n" +
                "      {\n" +
                "        \"name\": \"c++\",\n" +
                "        \"author\": \"liwu\"\n" +
                "      }\n" +
                "    ]\n" +
                "  }";
        Gson gson = new Gson();
        JsonBean jsonBean = gson.fromJson(jsonStr, JsonBean.class);
        String name = jsonBean.getName();
        int age = jsonBean.getAge();
        List<JsonBean.Book> books = jsonBean.getBooks();
        for (JsonBean.Book book : books) {
            String bookName = book.getName();
            String author = book.getAuthor();
            System.out.println("book " + bookName + " " + author);
        }
        System.out.println("name是 " + name + "  " + age);}
}
